package com.sjgs.gis.config;


import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

@NoArgsConstructor
@ConfigurationProperties(prefix = "kvstore")
public class KVStoreProperties {

    private String rootDir = "/data/kv";
    private String snapshotDir ="/data/kvsst";
    private String backupDir ="/data/kvbak";
    private boolean sync = false;
    // For the same reason(See the comment of 'sync' field), we also
    // don't need WAL, which can improve performance.
    //
    // If `sync` is true, `disableWAL` must be set false
    private boolean disableWal = true;
    // https://github.com/facebook/rocksdb/wiki/Checkpoints
    private boolean fastSnapshot = false;
    private boolean asyncSnapshot = false;
    private Integer maxDatabase = 8;

    private final Rocks rocks = new Rocks();

    public String getRootDir() {
        return rootDir;
    }

    public void setRootDir(String rootDir) {
        this.rootDir = rootDir;
    }

    public String getSnapshotDir() {
        return snapshotDir;
    }

    public void setSnapshotDir(String snapshotDir) {
        this.snapshotDir = snapshotDir;
    }

    public String getBackupDir() {
        return backupDir;
    }

    public void setBackupDir(String backupDir) {
        this.backupDir = backupDir;
    }

    public Integer getMaxDatabase() {
        return maxDatabase;
    }

    public void setMaxDatabase(Integer maxDatabase) {
        this.maxDatabase = maxDatabase;
    }

    public boolean isSync() {
        return sync;
    }

    public void setSync(boolean sync) {
        this.sync = sync;
    }

    public boolean isDisableWal() {
        return disableWal;
    }

    public void setDisableWal(boolean disableWal) {
        this.disableWal = disableWal;
    }

    public boolean isFastSnapshot() {
        return fastSnapshot;
    }

    public void setFastSnapshot(boolean fastSnapshot) {
        this.fastSnapshot = fastSnapshot;
    }

    public boolean isAsyncSnapshot() {
        return asyncSnapshot;
    }

    public void setAsyncSnapshot(boolean asyncSnapshot) {
        this.asyncSnapshot = asyncSnapshot;
    }

    public Rocks getRocks() {
        return rocks;
    }

    @NoArgsConstructor
    public static class Rocks {
        private Boolean enabled = false;


        private long writeBufferSize = 32;
        private int maxOpenFiles = -1;
        private int maxWriteBufferNumber = 2;
        private int targetFileSizeBase = 32;

        public Boolean getEnabled() {
            return enabled;
        }

        public void setEnabled(Boolean enabled) {
            this.enabled = enabled;
        }


        public long getWriteBufferSize() {
            return writeBufferSize;
        }

        public void setWriteBufferSize(long writeBufferSize) {
            this.writeBufferSize = writeBufferSize;
        }

        public int getMaxOpenFiles() {
            return maxOpenFiles;
        }

        public void setMaxOpenFiles(int maxOpenFiles) {
            this.maxOpenFiles = maxOpenFiles;
        }

        public int getMaxWriteBufferNumber() {
            return maxWriteBufferNumber;
        }

        public void setMaxWriteBufferNumber(int maxWriteBufferNumber) {
            this.maxWriteBufferNumber = maxWriteBufferNumber;
        }

        public int getTargetFileSizeBase() {
            return targetFileSizeBase;
        }

        public void setTargetFileSizeBase(int targetFileSizeBase) {
            this.targetFileSizeBase = targetFileSizeBase;
        }
    }

}
